package net.dl.ss.dao.ibatis;

import java.sql.SQLException;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;

public class IbatisUtil {
	
	public static Object queryObject(SqlMapClient client, String query, Object queryParameter) throws SQLException {
		client.startTransaction();
		try {
			Object o = client.queryForObject(query, queryParameter);
			client.commitTransaction();
			return o;
		}
		finally {
			client.endTransaction();
		}
	}

	public static Object queryObject(SqlMapClient client, String query) throws SQLException {
		client.startTransaction();
		try {
			Object o = client.queryForObject(query);
			client.commitTransaction();
			return o;
		}
		finally {
			client.endTransaction();
		}
	}

	@SuppressWarnings("unchecked")
    public static List queryList(SqlMapClient client, String query) throws SQLException {
		client.startTransaction();
		try {
			Object o = client.queryForList(query);
			client.commitTransaction();
			return (List) o;
		}
		finally {
			client.endTransaction();
		}
	}

	@SuppressWarnings("unchecked")
    public static List queryList(SqlMapClient client, String query, Object queryParameter) throws SQLException {
		client.startTransaction();
		try {
			Object o = client.queryForList(query, queryParameter);
			client.commitTransaction();
			return (List) o;
		}
		finally {
			client.endTransaction();
		}
	}
	
}

